//
//  DanmakuTableViewCell.swift
//  live
//
//  Created by melvyn on 2018/9/16.
//  Copyright © 2018 NEET. All rights reserved.
//

import UIKit

class DanmakuTableViewCell: UITableViewCell {

    @IBOutlet weak var titleTextLabel: UILabel!
    @IBOutlet weak var uLvTextLabel: UILabel!
    @IBOutlet weak var nicknameTextLabel: UILabel!
    @IBOutlet weak var commentTextLabel: UILabel!
    
    var viewModel: DanmakuViewModel? {
        didSet {
            guard let viewModel = viewModel else {
                return
            }
            
            viewModel.content
            .drive(commentTextLabel.rx.text)
            .disposed(by: rx.disposeBag)
            
            viewModel.nickname
            .drive(nicknameTextLabel.rx.text)
            .disposed(by: rx.disposeBag)
            
            viewModel.uLv
            .drive(uLvTextLabel.rx.text)
                .disposed(by: rx.disposeBag)
        
            viewModel.title
            .drive(titleTextLabel.rx.text)
                .disposed(by: rx.disposeBag)
            
            viewModel.title
                .drive(onNext: {[weak self] in
                    self?.titleTextLabel.textEdgeInsets = $0 == nil ? .zero : UIEdgeInsets(top: 2, left: 5, bottom: 2, right: 5)
                })
            .disposed(by: rx.disposeBag)
        }
    }
}
